package com.ld.security.auth.sdk.handler;


import com.ld.security.common.core.base.vo.ExceptionVo;
import com.ld.security.common.tomcat.util.RespUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * @Description: 登陆成功处理类
 * @ClassName:SecurityAuthenticationSuccessHandler
 * @Author:Player
 * @Date:2019-05-30 17:16
 **/
@Component
public class SecurityAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        UserDetails principal = (UserDetails) authentication.getPrincipal();


        ExceptionVo vo =   new ExceptionVo();
        vo.setLabel("登录成功");
        RespUtil.writeJson(authentication);
    }
}
